package com.xiguaji.tiktok.v1.tiktok.comparison.repository;

import com.xiguaji.tiktok.v1.tiktok.comparison.dto.BloggerResponse;
import com.xiguaji.tiktok.v1.tiktok.comparison.model.ComparisonHistoryDetail;
import org.springframework.data.jdbc.repository.query.Modifying;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface ComparisonHistoryDetailRepository extends CrudRepository<ComparisonHistoryDetail,Long> {

    @Query("select REPLACE(REPLACE (REPLACE (avatar, 'sign-sg', 'amd-va'), 'sign-va', 'amd-va'),'webp','jpeg') avatar,nickname,region,unique_id,enterprise_verify_reason,custom_verify,uid " +
            "from comparison_history_detail where comparison_history_id = :comparisonHistoryId order by sort asc")
    List<BloggerResponse> getSimpleDataByComparisonHistoryId(long comparisonHistoryId);

    List<ComparisonHistoryDetail> findByComparisonHistoryIdOrderBySortAsc(long comparisonHistoryId);

    @Modifying
    @Query("delete from comparison_history_detail where  comparison_history_id = :comparisonHistoryId")
    void deleteByComparisonHistoryId(long comparisonHistoryId);
}
